<?php
  /***************************************************************
   * @file: view.php
   * @author: Neo
   * @mail: xq262144@gmail.com
   * @date: 
   * @description:
   * this file is the view manage of the framework
   ***************************************************************/
   
  if (!defined('SYS_BASEPATH')) {echo "No script access allowed!"; header("HTTP/1.0 404 Not Found"); } 
  
  class View
  {
    private $view_name;
    private $displayed = false;
    private $data = array();
    
    public function __construct($view_name) {
       $this->view_name = $view_name; 
    }  
    
    public function assign($data) {
      if (empty($data) || !is_array($data)) {
        return false;
      }
      $this->data = array_merge($this->data, $data);
      return $this;
    }
    
    public function display() {
      if ($this->displayed) { return; }
      extract($this->data);
      require_once(SYS_VIEW . '/' . $this->view_name . '.php');
      $this->displayed = true;
    }                              
  }